import { getItem } from '@/utils/storage'
import { urlConf } from '@/config/resource'

const sharePrams = (from, buttonId) => {
  const curPage = getCurrentPages()[0].route

  const { user_id } = getItem('userIds')
  const { id } = getItem('user_info')

  const share_id = curPage.includes('my/index') ? id : user_id
  const title = '真实家长帮孩子找对象的免费相亲平台，本地家长都在用'
  let path = '/pages/launch/index'
  if (from == 'button') {
    if (buttonId != 'recommend') {
      path = '/subPages/details/index?id=' + share_id
    }
  }
  return {
    title,
    path,
    imageUrl: urlConf + 'common/fx.png',
    success () {
      console.log('分享成功')
    }
  }
}

const share = {
  // 分享到好友
  onShareAppMessage (e) {
    return sharePrams(e.from, e.target?.id)
  },
  // 分享到朋友圈
  onShareTimeline (e) {
    return sharePrams(e.from, e.target?.id)
  }
}
export default share
